Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2BundleManager = require("BundleManager");
var def_AudioManager = /* */function () {
  function _ctor() {
    babel_classCallCheck(this, _ctor);
    this.audioMap = {};
    this.muteBgm = false;
    this.muteEffect = false;
    this.bgmName = "";
  }
  babel_createClass(_ctor, [{
    key: "playMusic",
    value: function playMusic(e, t, a) {
      var _this5 = this;
      if (this.muteBgm) {
        return;
      }
      var _i;
      null == t && (t = false);
      _i = null != a ? a : 1;
      var s = $2BundleManager.default.instance.getBundleRes("Audio", e, cc.AudioClip);
      if (s) {
        cc.audioEngine.stop(this.audioMap[this.bgmName]);
        this.audioMap[e] = cc.audioEngine.play(s, t, _i);
        this.bgmName = e;
      } else {
        $2BundleManager.default.instance.loadBundleRes("Audio", e, cc.AudioClip, function () {
          s = $2BundleManager.default.instance.getBundleRes("Audio", e, cc.AudioClip);
          cc.audioEngine.stop(_this5.audioMap[_this5.bgmName]);
          _this5.audioMap[e] = cc.audioEngine.play(s, t, _i);
          _this5.bgmName = e;
        });
      }
    }
  }, {
    key: "playEffect",
    value: function playEffect(e) {
      var _this6 = this;
      var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
      var a = arguments.length > 2 ? arguments[2] : undefined;
      var _i2 = arguments.length > 3 ? arguments[3] : undefined;
      var s = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "";
      if ("" == e) {
        return;
      }
      if (this.muteEffect) {
        return;
      }
      null == _i2 && (_i2 = false);
      var o = $2BundleManager.default.instance.getBundleRes("Audio", e, cc.AudioClip);
      if (o) {
        this.audioMap[e + s] = cc.audioEngine.play(o, _i2, t);
      } else {
        $2BundleManager.default.instance.loadBundleRes("Audio", e, cc.AudioClip, function () {
          o = $2BundleManager.default.instance.getBundleRes("Audio", e, cc.AudioClip);
          _this6.audioMap[e + s] = cc.audioEngine.play(o, _i2, t);
        });
      }
      if (a) {
        this.pauseBgm();
        cc.audioEngine.setFinishCallback(this.audioMap[e], function () {
          _this6.resumeBgm();
        });
      }
    }
  }, {
    key: "pauseBgm",
    value: function pauseBgm() {
      cc.audioEngine.pause(this.audioMap[this.bgmName]);
    }
  }, {
    key: "resumeBgm",
    value: function resumeBgm() {
      cc.audioEngine.resume(this.audioMap[this.bgmName]);
    }
  }, {
    key: "stopAll",
    value: function stopAll() {
      cc.audioEngine.stopAll();
    }
  }, {
    key: "stopEffect",
    value: function stopEffect(e) {
      if (null != this.audioMap[e]) {
        cc.audioEngine.stop(this.audioMap[e]);
        delete this.audioMap[e];
      }
    }
  }, {
    key: "pauseAll",
    value: function pauseAll() {
      cc.audioEngine.pauseAll();
    }
  }, {
    key: "resumeAll",
    value: function resumeAll() {
      cc.audioEngine.resumeAll();
    }
  }], [{
    key: "instance",
    get() {
      this._instance || (this._instance = new _ctor());
      return this._instance;
    }
  }]);
  return _ctor;
}();
exports.default = def_AudioManager;
def_AudioManager._instance = null;